<c:if test="${sessionBean.ejbSession.owner==null}" >
    <jsp:forward page="../login.jsp" />
</c:if>
<style type="text/css">
    .rich-menu-item {
        text-align: left;
    }
    .rich-table-cell{
        font-size: 15px;
    }
</style>
<f:view>
    <h:form>
        <h:panelGrid columns="2" >
            <h:outputText value="Home of #{sessionBean.ejbSession.owner.email} "  style="font-size: 20px; font-weight: bold;"/>
            <rich:toolBar id="toolBarUser" itemSeparator="line" width="650" style="right:5px; top:5px; position:absolute;">
                <h:commandLink value="Log out" action="#{loginBean.logout}" />
                <h:outputLink value="/site/faces/welcome.jsp" >
                    <h:outputText value="Welcome Page" />
                </h:outputLink>
                <h:outputLink value="/site/faces/admin/adminadmin.jsp" rendered="#{sessionBean.ejbSession.owner.adminUser}">
                    <h:outputText value="Admin panel" />
                </h:outputLink>
                <h:commandLink value="User Settings" action="settingsUser" />
                <h:panelGrid columns="4" width="100%" >
                <rich:dropDownMenu value="Post to Classifieds" direction="bottom-right" >
                    <rich:menuItem value="Job" action="#{postBean.createJobPosting}" focus="title" >
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.job}" value="#{null}"/>
                        <f:setPropertyActionListener target="#{postBean.back}" value="#{1}"/>
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.currentSite}" value="#{registerUserBean.postingSite}"/>
                    </rich:menuItem>
                    <rich:menuItem value="Resume" action="#{postBean.createResumePosting}" focus="title">
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.resume}" value="#{null}"/>
                        <f:setPropertyActionListener target="#{postBean.back}" value="#{1}"/>
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.currentSite}" value="#{registerUserBean.postingSite}"/>
                    </rich:menuItem>
                    <rich:menuItem value="House" action="#{postBean.createHousPosting}" focus="title" >
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.hous}" value="#{null}"/>
                        <f:setPropertyActionListener target="#{postBean.back}" value="#{1}"/>
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.currentSite}" value="#{registerUserBean.postingSite}"/>
                    </rich:menuItem>
                    <rich:menuItem value="Sale" action="#{postBean.createSalePosting}" focus="title" >
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.sale}" value="#{null}"/>
                        <f:setPropertyActionListener target="#{postBean.back}" value="#{1}"/>
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.currentSite}" value="#{registerUserBean.postingSite}"/>
                    </rich:menuItem>
                    <rich:menuItem value="Gig" action="#{postBean.createGigPosting}" focus="title" >
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.gig}" value="#{null}"/>
                        <f:setPropertyActionListener target="#{postBean.back}" value="#{1}"/>
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.currentSite}" value="#{registerUserBean.postingSite}"/>
                    </rich:menuItem>
                    <rich:menuItem value="Service" action="#{postBean.createServicePosting}" focus="title" >
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.service}" value="#{null}"/>
                        <f:setPropertyActionListener target="#{postBean.back}" value="#{1}"/>
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.currentSite}" value="#{registerUserBean.postingSite}"/>
                    </rich:menuItem>
                    <rich:menuItem value="Personal" action="#{postBean.createPersonalPosting}" focus="title" >
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.personal}" value="#{null}"/>
                        <f:setPropertyActionListener target="#{postBean.back}" value="#{1}"/>
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.currentSite}" value="#{registerUserBean.postingSite}"/>
                    </rich:menuItem>
                    <rich:menuItem value="Community" action="#{postBean.createCommunityPosting}" focus="title" >
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.community}" value="#{null}"/>
                        <f:setPropertyActionListener target="#{postBean.back}" value="#{1}"/>
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.currentSite}" value="#{registerUserBean.postingSite}"/>
                    </rich:menuItem>
                    <rich:menuItem value="Event" action="#{postBean.createEventPosting}" focus="title" >
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.event}" value="#{null}"/>
                        <f:setPropertyActionListener target="#{postBean.back}" value="#{1}"/>
                        <f:setPropertyActionListener target="#{sessionBean.ejbSession.currentSite}" value="#{registerUserBean.postingSite}"/>
                    </rich:menuItem>
                </rich:dropDownMenu>
                <h:outputText value=" in Site: " />
                <h:outputText value="#{sessionBean.ejbSession.currentSite.site}" style="color:#CC0000; font-weight: bold;"/>
                <%--<h:selectOneMenu value="#{registerUserBean.siteId}" >
                    <c:forEach var="site" items="#{adminBean.listAll}" >
                        <f:selectItem
                            itemValue="#{site.id}"
                            itemLabel="#{site.site}"/>
                    </c:forEach>
                </h:selectOneMenu>--%>
                </h:panelGrid>
            </rich:toolBar>
        </h:panelGrid>
    </h:form>
        <rich:spacer height="20" />
        <h4><h:outputText value="#{registerUserBean.sizePosts} most recent postings of #{sessionBean.ejbSession.owner.numberOfPostings} maximum returned"/></h4>
    <div align="center">
    <a4j:region>
    <h:form id="postingsUserForm">
        <a4j:status>
            <f:facet name="start">
                <h:graphicImage  value="/images/ajax_process.gif"/>
            </f:facet>
        </a4j:status>
        <h:messages globalOnly="true" />
        <rich:dataTable style="font-size:15px;" id="postingsUserTable" rows="#{sessionBean.ejbSession.owner.numberOfPostings}" value="#{registerUserBean.postsOwner}" var="post" border="1" >
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Type" />
                </f:facet>
                <h:outputText value="#{post.type}" />
            </rich:column>
            
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Code" />
                </f:facet>
                <h:outputText value="#{post.code}" />
            </rich:column>
            
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Publish Date" />
                </f:facet>
                <h:outputText value="#{post.publishDate}" rendered="#{post.status=='active'}" >
                    <f:convertDateTime type="date" dateStyle="medium"/>
                </h:outputText>
                <h:outputText value=" - " rendered="#{post.status=='pending'}" />
            </rich:column>
            
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Site" />
                </f:facet>
                <h:outputText value="#{post.site.site}" />
            </rich:column>
            
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Categorie" />
                </f:facet>
                <h:outputText value="#{post.categorie}" />
            </rich:column>
            
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Title" />
                </f:facet>
                <h:commandLink value="#{post.title}" action="#{postBean.evaluationViewPosting}">
                    <f:setPropertyActionListener target="#{postBean.post}" value="#{post}"/>
                    <f:setPropertyActionListener target="#{postBean.back}" value="#{1}"/>
                </h:commandLink>
            </rich:column>
            
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Fee" />
                </f:facet>
                <h:outputText value="#{post.fee}" />
            </rich:column>
            
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Options" />
                </f:facet>
                <h:commandButton value="Edit" action="#{postBean.evaluationEditPosting}" >
                    <f:setPropertyActionListener target="#{postBean.post}" value="#{post}"/>
                </h:commandButton>
                <a4j:commandButton value="Delete" action="#{postBean.delete}" onclick="if(!confirm('Your Post will be deleted. Are you sure?'))return false" reRender="postingsUserForm">
                    <f:setPropertyActionListener target="#{postBean.post}" value="#{post}"/>
                </a4j:commandButton>
                <a4j:commandButton value="To Publish" action="#{postBean.toPublish}" onclick="if(!confirm('After yur post has been published you can not go back'))return false" rendered="#{post.status=='pending'}" reRender="postingsUserForm">
                    <f:setPropertyActionListener target="#{postBean.post}" value="#{post}"/>
                </a4j:commandButton>
            </rich:column>
            
        </rich:dataTable>
        <rich:spacer height="10" />
        <rich:datascroller for="postingsUserTable" maxPages="5" page="#{sessionBean.pagePostsUser}" />
    </h:form>
    </a4j:region>
    </div>
    <h:form>
        <h:outputLink value="/site/faces/welcome.jsp" >
            <h:outputText value="Back to Welcome Page"></h:outputText>
        </h:outputLink>
    </h:form>
    <rich:separator height="1" />
</f:view>